/*  File Name	: Acceptor.h
 *  Author		: Javie Pong
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-3-20
 *  Description:
 */

#ifndef ACCEPTOR_H_
#define ACCEPTOR_H_

#include "Reactor.h"

template<class SVC_HANDLER,class PEER_ACCEPTOR>
class Acceptor:virtual public EventHandler
{
public:
	typedef PEER_ACCEPTOR 	AcceptorType;
	typedef SVC_HANDLER		SvcType;

	Acceptor(Reactor *reactor=NULL,int port=0,std::string ip="");

	virtual ~Acceptor();

	virtual int open(int port,Reactor *reactor=Reactor::instance(),
			std::string ip="");

	virtual int handle_input(int handle);

	virtual int handle_output(int handle);

	virtual int handle_close(int handle=INVALID_HANDLER,
			ReactorMask mask=EventHandler::ALL_MASK);

	virtual int handle_timeout(void);

	virtual const int get_handle(void);

	const PEER_ACCEPTOR &acceptor(void);

protected:
	virtual int make_svc_handler(SVC_HANDLER *&svc);

	virtual int accept_svc_handler(SVC_HANDLER *svc);

	virtual int active_svc_handler(SVC_HANDLER *svc);

private:
	AcceptorType acceptor_;
	std::string ip_;
	int port_;

	bool is_open_;
};

#include "Acceptor.cpp"
#endif /* ACCEPTOR_H_ */
